import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class test606 {
    static class TreeNode{
        public char val;
        public TreeNode right;
        public TreeNode left;

        public TreeNode(char val) {
            this.val = val;
        }

    }

    public String tree2str(TreeNode root) {
        List<Integer> in = new ArrayList<>();

        StringBuilder sbu = new StringBuilder();
        tree2strChild(root,sbu);
        return sbu.toString();
    }

    public void tree2strChild(TreeNode root, StringBuilder sbu){
        if(root == null){
            return;
        }
        sbu.append(root.val);
        // 先递归左树，左树不为空；左树为空，右树也为空（直接返回），右树不为空
        if(root.left != null){
            sbu.append("(");
            tree2strChild(root.left,sbu);
            sbu.append(")");
        }else {
            if(root.right == null){
                return;
            }else {
                sbu.append("()");
            }
        }

        // 递归右树
        if(root.right != null){
            sbu.append("(");
            tree2strChild(root.right,sbu);
            sbu.append(")");
        }else {
            return;
        }

        String i = "abc";
        i.length();
        i.charAt(1);
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
    }

}
